package cn.feizhu.aimarket.exception;

import cn.feizhu.aimarket.common.BaseResponse;
import cn.feizhu.aimarket.common.ResultUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    public BaseResponse<?> businessExceptionHandler(BusinessException e) {
        log.error("BusinessException", e);
        return ResultUtils.error(e.getCode(), e.getMessage());
    }

    @ExceptionHandler(RuntimeException.class)
    public BaseResponse<?> runTimeExceptionHandler(RuntimeException e) {
        log.error("RunTimeException", e);
        return ResultUtils.error(ErrorCode.SYSTEM_ERROR, "system error");
    }

}
